﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MODEL;
using GalaSoft.MvvmLight.Messaging;
using GalaSoft.MvvmLight;
using ViewModel.AlertCreate;

namespace msap.AlertCreate.AlertMake
{
    /// <summary>
    /// Index.xaml 的交互逻辑
    /// </summary>
    public partial class IndexForm : Page
    {
        public IndexForm()
        {
            InitializeComponent();

            Messenger.Default.Register<ViewModelBase>(this, "AlertCreate_ShowAlertEditForm", true ,ShowAlertEidtWindow);
            Messenger.Default.Register<ViewModelBase>(this, "AlertCreate_ShowAlertDetailForm",true, ShowAlertInfoForm);
            Messenger.Default.Register<object>(this, "AlertCreate_ShowChooseAlertTypeDialog", ShowChooseAlertTypeDialog);
            Messenger.Default.Register<ViewModelBase>(this, "AlertCreate_ShowMessageReleaseDialog",true ,ShowMessageReleaseDialog);
        }

        private void ShowMessageReleaseDialog(ViewModelBase vm)
        {
            MessageRelease.MessageRelease.IndexForm form = new MessageRelease.MessageRelease.IndexForm();           
            UserControls.CustomizeDialog dialog = new UserControls.CustomizeDialog(form);
            dialog.ShowDialog();
        }

        private void ShowChooseAlertTypeDialog(object o)
        {
            ChooseAlterTypeDialog dialog = new ChooseAlterTypeDialog();
            dialog.ShowDialog();
            if (!dialog.ChooseAlertType.HasValue)
            {
                return;
            }

            switch (dialog.ChooseAlertType)
            {
                case AlertType.NormalAlert:
                    ((AlertMakeViewModel)this.DataContext).NormalAlertCommand.Execute(null);
                    break;
                case AlertType.CustomerAlert:
                    ((AlertMakeViewModel)this.DataContext).InsertAlertCommand.Execute(null);
                    break;
                default: return;                    
            }
        }

        private void ShowAlertEidtWindow(ViewModelBase vm)
        {
            EditForm editForm = new EditForm();
            editForm.DataContext = vm;
            editForm.Owner = Window.GetWindow(this);
            editForm.ShowDialog();
        }

        private void ShowAlertInfoForm(ViewModelBase vm)
        {
            DetailForm alertInfo = new DetailForm();
            alertInfo.DataContext = vm;
            alertInfo.Owner = Window.GetWindow(this);
            alertInfo.ShowDialog();
        }     
    }
}
